package cn.tedu.submarine_1;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

//海洋对象类，所有对象的超类
public abstract class SeaObject {
    public static final int LIVE=0;
    public static final int DEAD=0;
    private int state=LIVE;
    private int width;
    private int height;
    private int x;
    private int y;
    private int speed;

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }
    public SeaObject(int width,int height){
        this.height=height;
        this.width=width;
        x=-width;
        Random rand=new Random();
        y=rand.nextInt(World.HEIGHT-height-150+1)+150;
        speed=rand.nextInt(3)+1;
    }
    public SeaObject(int width,int height,int x,int y,int speed){
        this.width=width;
        this.height=height;
        this.x=x;
        this.y=y;
        this.speed=speed;
    }

    public abstract void move() ;

    public abstract ImageIcon getImage();
    public boolean isLive() {
        return state==LIVE;
    }
    //判断对象是否是死了的
    public boolean isDead(){
        return state==DEAD;
    }
    public void painttImage(Graphics g){
        if(this.isLive()){
            this.getImage().paintIcon(null,g,this.x,this.y);
        }
    }



}
